﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MarkDownFileSplitter.Meilisearch
{
    public partial class FormIndexCreaterByDocument : Form
    {
        private bool isAddDocumentMode = false;

        public FormIndexCreaterByDocument()
        {
            InitializeComponent();
        }

        private void FormIndexCreaterByDocument_Load(object sender, EventArgs e)
        {
            this.addDocumentControl1.IsNewIndex = !isAddDocumentMode;

            if (isAddDocumentMode)
            {
                this.Text = "补充Document";
            }
            else
            {
                this.Text = "新增Index";
            }
        }

        public void SetAddDocumentMode(string indexUid, string primaryKey)
        {
            isAddDocumentMode = true;

            // 在窗体加载后设置索引信息
            this.Load += (s, e) =>
            {
                // 获取现有的属性名称
                Task.Run(async () =>
                {
                    var attributeNames = await MeilisearchUploader.Instance.GetDocumentAttributeNames(indexUid);

                    this.Invoke(() =>
                    {
                        this.addDocumentControl1.SetIndexSetting(indexUid, primaryKey, attributeNames);
                    });
                });
            };
        }

    }
}
